package com.erp.framework.types;

import java.math.BigDecimal;
import java.math.BigInteger;

import com.erp.framework.SimpleConstants;

public class CustomBigDecimal extends BigDecimal implements SimpleConstants {

    public int scale = 0;

    /**
     * @param unscaledVal
     */
    public CustomBigDecimal(String val) {
        super(val);
    }

    /**
     * @param unscaledVal
     */
    public CustomBigDecimal(int val) {
        super(val);
    }

    /**
     * @param unscaledVal
     */
    public CustomBigDecimal(double val) {
        super(val);
    }

    /**
     * @param unscaledVal
     */
    public CustomBigDecimal(BigDecimal val) {
        //super(val.doubleValue());
    	super(String.valueOf(val));
    }

    /**
     * @param unscaledVal
     */
    public CustomBigDecimal(BigInteger val) {
        super(val.intValue());
    }

    /**
     * @param unscaledVal
     * @param val
     */
    public CustomBigDecimal(BigInteger unscaledVal, int val) {
        super(unscaledVal, val);
    }

//    protected String getValueString(int signum, String intString, int scale) {
//        /* Insert decimal point */
//        StringBuffer buf;
//        int insertionPoint = intString.length() - scale;
//        if (insertionPoint == 0) { /* Point goes right before intVal */
//            return (signum < 0 ? "-0." : "0.") + intString;
//        } else if (insertionPoint > 0) { /* Point goes inside intVal */
//            buf = new StringBuffer(intString);
//            buf.insert(insertionPoint, '.');
//            if (signum < 0)
//                buf.insert(0, '-');
//        } else { /* We must insert zeros between point and intVal */
//            buf = new StringBuffer(3 - insertionPoint + intString.length());
//            buf.append(signum < 0 ? "-0." : "0.");
//            for (int i = 0; i < -insertionPoint; i++)
//                buf.append('0');
//            buf.append(intString);
//        }
//        return buf.toString();
//    }

    public static CustomBigDecimal customize(String val){
        if(val == null){
            return null;
        } else {
            return new CustomBigDecimal(val);
        }
    }
    
    public static CustomBigDecimal customize(BigDecimal val){
        if(val == null){
            return null;
        } else {
            return new CustomBigDecimal(val);
        }
    }
    
    public static CustomBigDecimal customize(BigInteger val){
        if(val == null){
            return null;
        } else {
            return new CustomBigDecimal(val);
        }
    }
    
    public String toString() {
        //return this.getValueString(signum(), super.toString(), scale);
    	return super.toString();
    }
}
